import requests
import json

headers = {
    "Content-Type": "application/json; charset=UTF-8"
}


def invoke_java(uri, data):
    return json.loads(
        requests.request(url='http://localhost:8088/dingwei' + uri, method='post', headers=headers,
                         data=json.dumps(data)).text)


def turn_fit_extend(points):
    return invoke_java('/turnFitExtend', {"pointList": points})


def multi_avg(point_lists):
    param = []
    for pl in point_lists:
        param.append({"pointList": pl})
    return invoke_java('/multiAvg', param)


def is_inner(points, point):
    return invoke_java('/isInner', {
        'pointList': {"pointList": points},
        'point': point
    })


def wgs84_to_gcj02(points):
    return invoke_java('/wgs84ToGcj02', {
        'gpsList': points
    })


def gcj02_to_wgs84(points):
    return invoke_java('/gcj02ToWgs84', {
        'gpsList': points
    })
